#include "regist.h"
#include "ui_regist.h"
#include "form.h"

Regist::Regist(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Regist)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
}

Regist::~Regist()
{
    delete ui;
}

void Regist::on_pushButton_2_clicked()
{

    Form *w = new Form;
    w->show();
    this->close();
}

void Regist::on_pushButton_clicked()
{

    sqlite_Init();
    QString username = ui->lineEdit_username->text();
    QString password = ui->lineEdit_passward->text();
    QString surepass = ui->lineEdit_surepassward->text();
    //判断密码是否一致
    if(password == surepass)
    {
        QString sql=QString("insert into user(username,password) values('%1','%2');")
                .arg(username).arg(password);
        //创建执行语句对象
        QSqlQuery query;
        //判断执行结果
        if(!query.exec(sql))
        {
            qDebug()<<"insert into error";
            QMessageBox::information(this,"注册认证","插入失败！");
        }
        else
        {
            qDebug()<<"insert into success";
            QMessageBox::information(this,"注册认证","插入成功！");
            Form *w = new Form;
            w->show();
            this->close();
        }

    }else{
        QMessageBox::information(this,"注册认证","两次密码输入不一致");
    }

}
